<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        .hide {
            display: none;
        }

        .c1 {
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, .5);
            z-index: 99;
            margin-top: 12%;
        }

        .c2 {
            background-color: white;
            position: fixed;
            width: 400px;
            height: 300px;
            top: 50%;
            left: 50%;
            z-index: 100;
            margin-top: -150px;
            margin-left: -200px;
            padding-top: 2%;
            padding-left: 2%;
        }

        #modal p {
            margin-left: 80px;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            选择工单-创建检测记录
        </div>
    </header>
    <div id="shade" class="c1 hide"></div>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" >日期</div>
                    <div class="aui-list-item-input" onclick="timePicker();">
                        <input type="text" placeholder="选择日期" class="aui-input"
                            id="dateTime">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">产线</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请选择产线" id="workCenterCode" value=""
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCenterLine()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请选择物料" id="mrlCode" value="" 
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectMrl()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">规格</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请输入规格" id="drawing" value="" >
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">工单状态</div>
                    <div class="aui-list-item-input">
                        <select id="gdState" style="font-size: 14px;">
                            <option value="发布" selected="true">发布</option>
                            <option value="开工">开工</option>
                            <option value="完工">完工</option>
                            <option value="暂停">暂停</option>
                        </select>
                    </div>
                </div>
            </li>
        </ul>
        <div style="padding-top:2%;"></div>
         <!--弹出备注 -->
        <!-- <div id="shade" class="c1"></div> -->
        <div id="modal" class="c2 hide">
            <p style="margin-left: 10px;font-size: 1rem;font-weight: 500;color: #212121;text-align: center;">创建检测单记录</p>
            <ul class="aui-list aui-form-list" style="margin-top: 1%;">
                <li class="aui-list-item" id="chkmrlQtyItem">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">备注</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="备注" id="remark" />
                            <input type="text" id="workCenterCode1" style="display: none;" />
                            <input type="text" id="workCenterName" style="display: none;" />
                            <input type=" text" id="workOrderCode" style="display: none;" />
                            <input type=" text" id="mrlCode1" style="display: none;"  />
                            <input type=" text" id="drawing1" style="display: none;" />
                            <input type=" text" id="mrlName" style="display: none;" />
                            <input type=" text" id="create_date" style="display: none;" />
                            <input type=" text" id="reviewNum" style="display: none;" />
                            <input type=" text" id="lotCode" style="display: none;" />
                        </div>
                    </div>
                </li>
            </ul>
            <footer class=" aui-bar aui-bar-tab" style="position: absolute;">
                <div class="aui-btn aui-btn-info" style="width:30%;margin-left:2%;" onclick="Hide()">取消
                </div>
                <div class="aui-btn aui-btn-info" style="width:30%;margin-left:2%;" onclick="deal()">确定
                </div>
            </footer>
        </div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="search()">查询</div>

        <ul class="ui-selectee" id="tbodyHtml">

        </ul>
        <p></p>
        <p></p>
    </div>
    <div style="height:60px;"></div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";

    var workCenterGid = ""; //产线GID
    var workCenterCode = ""; //产线编码
    var workCenterName = ""; //产线名称

    var mrlId = ""; //物料ID
    var mrlCode = ""; //物料编码
    var mrlName = ""; //物料名称

    var list = [];
    var arrSave = [];//要带回的单据号
    
    let currentDate = new Date();
    let year = currentDate.getFullYear(); // 获取当前年份
    let month = (currentDate.getMonth() + 1) < 10 ? "0"+ (currentDate.getMonth() + 1)  : (currentDate.getMonth() + 1); // 获取当前月份，注意月份从0开始，所以要加1
    let day = currentDate.getDate() < 10 ? "0" + currentDate.getDate() : currentDate.getDate(); // 获取当前日期
    let time = year + '-' + month + '-' + day

    //初始化查询
    apiready = function () {
        $("#dateTime").val(time);
        search();
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //时间选择器
    function timePicker() {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#dateTime").val(date);
            }
        });
    }



    //选中产线
    function goSelectWorkCenterLine() {
        api.openWin({
            name: 'usmSelectLine',
            url: 'usmSelectLine.html',
            pageParam: {
                flag: "in",
                name: "qcmChkCreateRecord",
                mrlCode: "",
                lotCode: "",
                qty: ""
            }
        });
    }

    //产线选择后回调函数
    function setLineCode(id, code, name) {
        workCenterGid = id;
        workCenterCode = code;
        workCenterName = name;
        document.getElementById('workCenterCode').value = code + ":" + name;
    }

    //选择物料
    function goSelectMrl() {
        api.openWin({
            name: 'usmSelectMrl',
            url: 'usmSelectMrl.html',
            pageParam: {
                name: "qcmChkCreateRecord"
            }
        });
    }

    //物料选择后回调函数
    function setMrl(id, code, name) {
        mrlId = id;
        mrlCode = code;
        mrlName = name;
        document.getElementById('mrlCode').value = code + ":" + name;
    }

    function search() {
        if($("#mrlCode").val() == ""){
            mrlCode = ""
        }
        if($("#workCenterCode").val() == ""){
            workCenterCode = ""
        }
        var dateTime = $("#dateTime").val();
        var drawing = $("#drawing").val();
        var state = document.getElementById("gdState").value;
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchWorkOrder";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                workCenterCode: workCenterCode,
                mrlCode: mrlCode,
                un: un,
                createDate: dateTime,
                drawing:drawing,
                state:state
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    list = myobj.list;
                    setTable(list)
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });

                }
            }
        });
    }


    function setTable(list) {
        var html = "";
        for (var i = 0; i < list.length; i++) {
            html += "<div style='padding-top:4%;'></div>";
            html += "<li class='sortable ui-selectee ui-sortable' >";
            html += "<ul class='aui-list aui-media-list ui-selectee'>";
            html += "<li class='aui-list-item  ui-selectee' style='color: black !important;background-color: #addbef !important;'>";
            html += "<div class='aui-media-list-item-inner ui-selectee ' >";
            html += "<div class='aui-list-item-inner ui-selectee '>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>产线编码:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].workCenterCode + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>产线名称:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].workCenterName + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>工单号:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].workOrderCode + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料编码:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style = 'word-wrap:break-word; overflow:hidden;'>" + list[i].mrlCode + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>规格:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style = 'word-wrap:break-word; overflow:hidden;'>" + list[i].drawing + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料名称:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style = 'word-wrap:break-word; overflow:hidden;'>" + list[i].mrlName + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>工单状态:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style = 'word-wrap:break-word; overflow:hidden;'>" + list[i].state + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>计划日期:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style = 'word-wrap:break-word; overflow:hidden;'>" + list[i].create_date + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>追溯类型:</div>";
            html += "<div class='aui-list-item-inner ui-selectee' style = 'word-wrap:break-word; overflow:hidden;position: relative'>" + list[i].reviewType + "</div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee' style='position:absolute;algin:right;right:0' onclick='Show(\"" + list[i].workCenterCode + "\",\"" + list[i].workCenterName + "\",\"" + list[i].workOrderCode + "\",\"" + list[i].mrlCode + "\",\"" + list[i].drawing + "\",\"" + list[i].mrlName + "\",\"" + list[i].create_date + "\",\"" + list[i].reviewNum + "\",\"" + list[i].lotCode + "\");'>创建</div>";
            html += "</div>";

            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";
        }
        $api.html($api.byId("tbodyHtml"), html);
    };




    //选则返回函数
    function goPage() {
        api.closeWin();
        var name = api.pageParam.name;
        var str = "";
        for (var j = 0; j < arrSave.length; j++) {
            str = str + arrSave[j].distributeTaskCode + ",";
        }
        api.execScript({
            name: name,
            script: 'setPaTaskCode("' + str + '")'
        });
    }
    function Show(workCenterCode, workCenterName, workOrderCode, mrlCode, drawing, mrlName, create_date, reviewNum, lotCode) {
        document.getElementById('shade').classList.remove('hide');
        document.getElementById('modal').classList.remove('hide');
        document.getElementById('workCenterCode1').value = workCenterCode;
        document.getElementById('workCenterName').value = workCenterName;
        document.getElementById('workOrderCode').value = workOrderCode;
        document.getElementById('mrlCode1').value = mrlCode;
        document.getElementById('drawing1').value = drawing;
        document.getElementById('mrlName').value = mrlName;
        document.getElementById('create_date').value = create_date;
        document.getElementById('reviewNum').value = reviewNum;
        document.getElementById('lotCode').value = lotCode;
    }
    function Hide() {
        document.getElementById('shade').classList.add('hide');
        document.getElementById('modal').classList.add('hide');
        document.getElementById('workCenterCode1').value = "";
        document.getElementById('workCenterName').value = "";
        document.getElementById('workOrderCode').value = "";
        document.getElementById('mrlCode1').value = "";
        document.getElementById('drawing1').value = "";
        document.getElementById('mrlName').value = "";
        document.getElementById('create_date').value = "";
        document.getElementById('reviewNum').value = "";
        document.getElementById('lotCode').value = "";
        document.getElementById('remark').value = "";
    }

  //保存按钮
  function deal(workCenterCode,workCenterName,workOrderCode,mrlCode,drawing,mrlName,create_date,reviewNum,lotCode) {
        //产线编码
        var workCenterCode = document.getElementById('workCenterCode1').value;
        //产线名称
        var workCenterName = document.getElementById('workCenterName').value;
        //工单号
        var workOrderCode = document.getElementById('workOrderCode').value;
        //物料编码
        var mrlCode = document.getElementById('mrlCode1').value;
        //物料名称
        var mrlName = document.getElementById('mrlName').value;
        //规格
        var drawing = document.getElementById('drawing1').value;
        //追溯类型
        var reviewNum = document.getElementById('reviewNum').value;
        //批次号
        var lotCode = document.getElementById('lotCode').value;
        // 备注
        var remark = document.getElementById('remark').value;

        console.log('remark:' + remark );

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/qcmChkRecordSave";
        var data = {
            values: {
                workCenterCode: workCenterCode, 
                workCenterName: workCenterName,
                workOrderCode: workOrderCode, 
                mrlCode:mrlCode,
                mrlName:mrlName,
                drawing:drawing,
                reviewNum:reviewNum,
                lotCode:lotCode,
                remark:remark,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 'S') {
                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                    var map = myobj.data;
                    api.openWin({
                        name: 'qcmChkBillCreateOrDeal',
                        url: 'qcmChkBillCreateOrDeal.html',
                        pageParam: {
                            name: "qcmChkCreateRecord",
                            recordCode:map["recordCode"] 
                        }
                    });
                    Hide();
                } else {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    Hide();
                }
            } else {
                api.hideProgress();
            }
        });
    }
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }

</script>


</html>